Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint plugin no-undeclared-env-vars should detect known framework variables #9110

Merged
merged 20 commits into from
Sep 17, 2024

Conversation

dimitropoulos
Copy link
Contributor

@dimitropoulos dimitropoulos commented Sep 5, 2024

Description

This PR picks up from #8505

We currently do Framework Inference based on the package.json dependencies of the nearest package.json. turbo's Framework Inference support is per-package whereas this one wholesale allowslists all framework environment variables in every package.

The job of this PR, therefore, is to enable per-package framework detection.

I started by extracting this data to a json file, frameworks.json, so it can be shared between Rust and TypeScript.

TODOs:

  • extract the frameworks information in framework.rs into frameworks.json
  • search community to make sure that recursive package.json searching has no better method than fs.readFileSync
  • implement package.json search to resolve depencies
  • combine per-package resolution of those dependencies and regex allowlist values
  • update tests for the plugin
  • use the frameworks.json file to generate the table in using-environment-variables.mdx

Testing Instructions

After building the plugin (which will run it locally), open up packages/eslint-plugin-turbo/__fixtures__/framework-inference/apps/vite. Notice that there are no errors in index.js, but if you remove the vite dependency in package.json then there will be. Notice, also, that adding a next.js env var in this file (e.g. process.env.NEXT_PUBLIC_ZILTOID) will error as expected.

@turbo-orchestrator turbo-orchestrator bot added created-by: turborepo pkg: turbo-eslint eslint-config-turbo and eslint-plugin-turbo labels Sep 5, 2024
Copy link

vercel bot commented Sep 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 17, 2024 1:20am
8 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Sep 17, 2024 1:20am
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview Sep 17, 2024 1:20am
examples-gatsby-web ⬜️ Ignored (Inspect) Visit Preview Sep 17, 2024 1:20am
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview Sep 17, 2024 1:20am
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Sep 17, 2024 1:20am
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Sep 17, 2024 1:20am
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview Sep 17, 2024 1:20am
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview Sep 17, 2024 1:20am

Copy link

socket-security bot commented Sep 5, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@faker-js/[email protected] None 0 8.67 MB st-ddt
npm/[email protected] environment, eval, filesystem Transitive: network, shell, unsafe +118 183 MB siddhsuresh
npm/[email protected] None +3 74.5 kB right9ctrl
npm/[email protected] environment, filesystem Transitive: eval, network, shell, unsafe +60 25.5 MB pieh
npm/[email protected] None 0 9.75 kB stevemao
npm/[email protected] environment, filesystem, network Transitive: eval, unsafe +50 11.3 MB pi0
npm/[email protected] None 0 3.26 MB antfu, patak, soda, ...2 more

View full report↗︎

Copy link
Contributor

github-actions bot commented Sep 5, 2024

Hi there 👋

It looks like this PR introduces broken links to the docs, please take a moment to fix them before merging:

Broken link Type File
/repo/docs/guides/tools/typescript#you-likely-dont-need-a-tsconfigjson-file-in-the-root-of-your-project hash /repo-docs/crafting-your-repository/structuring-a-repository.mdx
#package-entrypoint-wildcards hash /repo-docs/guides/tools/typescript.mdx

Thank you 🙏

Copy link
Member

@tknickman tknickman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! A few suggestions and I want to test it out locally but overall looking great.

Copy link
Member

@tknickman tknickman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing to fix up that should fix the tests, and then let's ship it!

Copy link
Member

@tknickman tknickman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving so you can merge whenever the tests are good!

@dimitropoulos dimitropoulos merged commit b382e7e into main Sep 17, 2024
40 of 44 checks passed
@dimitropoulos dimitropoulos deleted the dimitri/eslint-config-turbo branch September 17, 2024 13:46
@anthonyshew
Copy link
Contributor

Very excited for this. Thanks, Dimitri!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docs Improvements or additions to documentation pkg: turbo-eslint eslint-config-turbo and eslint-plugin-turbo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants